-
Notifications
You must be signed in to change notification settings - Fork 30
/
Get-RemoteConnection.ps1
85 lines (69 loc) · 2.25 KB
/
Get-RemoteConnection.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<#
$Metadata = @{
Title = "Get Remote Connection"
Filename = "Get-RemoteConnection.ps1"
Description = ""
Tags = "powershell, function, remote"
Project = ""
Author = "Janik von Rotz"
AuthorContact = "http://janikvonrotz.ch"
CreateDate = "2013-04-08"
LastEditDate = "2014-03-03"
Version = "3.1.2"
License = @'
This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/3.0/ or
send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
'@
}
#>
function Get-RemoteConnection{
param(
[parameter(Mandatory=$false)]
[string[]]
$Name
)
#--------------------------------------------------#
# functions
#--------------------------------------------------#
function New-ObjectRemoteConnection{
param(
[string]$Name,
[string]$Server,
[string]$User,
[string]$Description,
[string]$SnapIns,
[string]$PrivatKey
)
New-Object PSObject -Property @{
Name = $Name
Server = $Server
User = $User
Description = $Description
SnapIns = $SnapIns
PrivatKey = $PrivatKey
}
}
#--------------------------------------------------#
# main
#--------------------------------------------------#
# load configurations
$ServerConfigs = Get-ChildItem -Path $PSconfigs.Path -Filter $PSconfigs.Server.Filter -Recurse | %{
[xml]$(get-content $_.FullName)} | %{
$_.Content.Server}
# check all-parameter
if(-not $Name){
$ServerConfigs | Sort Key
}elseif($Name){
$Matches = $ServerConfigs |
%{$Server = $_; $Name |
%{if(($Server.Key -contains $_) -or ($Server.Name -contains $_)){$Server}}}
if($Matches -eq $Null){
$Name | %{New-ObjectRemoteConnection -Name $_}
}else{
$Matches
}
}else{
throw "Enter values for the following parameters: Name[]"
}
}